// 权限定义
import { encryptPassword } from '../utils/auth';

export const permissions = [
  {
    code: 'system',
    name: '系统管理',
    children: [
      { code: 'system:view', name: '查看系统信息' },
      { code: 'system:config', name: '系统配置' },
      { code: 'system:backup', name: '数据备份' },
      { code: 'system:monitor', name: '系统监控' }
    ]
  },
  {
    code: 'product',
    name: '商品管理',
    children: [
      { code: 'product:view', name: '查看商品' },
      { code: 'product:add', name: '添加商品' },
      { code: 'product:edit', name: '编辑商品' },
      { code: 'product:delete', name: '删除商品' },
      { code: 'product:publish', name: '上下架商品' },
      { code: 'product:stock:update', name: '更新库存' },
      { code: 'product:price:update', name: '更新价格' },
      { code: 'product:batch', name: '批量操作' }
    ]
  },
  {
    code: 'category',
    name: '分类管理',
    children: [
      { code: 'category:view', name: '查看分类' },
      { code: 'category:add', name: '添加分类' },
      { code: 'category:edit', name: '编辑分类' },
      { code: 'category:delete', name: '删除分类' },
      { code: 'category:sort', name: '排序分类' }
    ]
  },
  {
    code: 'order',
    name: '订单管理',
    children: [
      { code: 'order:view', name: '查看订单' },
      { code: 'order:ship', name: '发货' },
      { code: 'order:cancel', name: '取消订单' },
      { code: 'order:export', name: '导出订单' },
      { code: 'order:refund', name: '订单退款' },
      { code: 'order:edit', name: '编辑订单' }
    ]
  },
  {
    code: 'refund',
    name: '售后管理',
    children: [
      { code: 'refund:view', name: '查看售后' },
      { code: 'refund:review', name: '审核售后' },
      { code: 'refund:execute', name: '执行退款' },
      { code: 'refund:reject', name: '拒绝售后' }
    ]
  },
  {
    code: 'user',
    name: '用户管理',
    children: [
      { code: 'user:view', name: '查看用户' },
      { code: 'user:edit', name: '编辑用户' },
      { code: 'user:disable', name: '禁用用户' },
      { code: 'user:reset', name: '重置密码' },
      { code: 'user:level', name: '调整等级' },
      { code: 'user:points', name: '积分管理' }
    ]
  },
  {
    code: 'admin',
    name: '管理员管理',
    children: [
      { code: 'admin:view', name: '查看管理员' },
      { code: 'admin:add', name: '添加管理员' },
      { code: 'admin:edit', name: '编辑管理员' },
      { code: 'admin:delete', name: '删除管理员' },
      { code: 'admin:disable', name: '禁用管理员' },
      { code: 'admin:reset', name: '重置密码' }
    ]
  },
  {
    code: 'role',
    name: '角色权限',
    children: [
      { code: 'role:view', name: '查看角色' },
      { code: 'role:add', name: '添加角色' },
      { code: 'role:edit', name: '编辑角色' },
      { code: 'role:delete', name: '删除角色' },
      { code: 'role:assign', name: '分配角色' }
    ]
  },
  {
    code: 'log',
    name: '日志管理',
    children: [
      { code: 'log:view', name: '查看日志' },
      { code: 'log:export', name: '导出日志' },
      { code: 'log:clear', name: '清理日志' }
    ]
  },
  {
    code: 'report',
    name: '数据报表',
    children: [
      { code: 'report:view', name: '查看报表' },
      { code: 'report:export', name: '导出报表' },
      { code: 'report:sales', name: '销售报表' },
      { code: 'report:user', name: '用户报表' }
    ]
  }
];

// 角色定义
export const mockRoles = [
  {
    id: 1,
    name: '超级管理员',
    code: 'super_admin',
    description: '拥有系统所有权限',
    permissions: permissions.flatMap(p => p.children.map(c => c.code)),
    createTime: Date.now() - 365 * 24 * 60 * 60 * 1000
  },
  {
    id: 2,
    name: '商品管理员',
    code: 'product_admin',
    description: '负责商品和分类的管理',
    permissions: [
      'product:view', 'product:add', 'product:edit', 'product:delete', 
      'product:publish', 'product:stock:update', 'product:price:update', 'product:batch',
      'category:view', 'category:add', 'category:edit', 'category:delete', 'category:sort'
    ],
    createTime: Date.now() - 180 * 24 * 60 * 60 * 1000
  },
  {
    id: 3,
    name: '订单管理员',
    code: 'order_admin',
    description: '负责订单和售后的处理',
    permissions: [
      'order:view', 'order:ship', 'order:cancel', 'order:export', 'order:refund', 'order:edit',
      'refund:view', 'refund:review', 'refund:execute', 'refund:reject',
      'user:view'
    ],
    createTime: Date.now() - 90 * 24 * 60 * 60 * 1000
  },
  {
    id: 4,
    name: '客服人员',
    code: 'customer_service',
    description: '处理用户咨询和售后',
    permissions: [
      'order:view',
      'user:view',
      'refund:view',
      'refund:review'
    ],
    createTime: Date.now() - 60 * 24 * 60 * 60 * 1000
  },
  {
    id: 5,
    name: '数据分析员',
    code: 'data_analyst',
    description: '负责数据分析和报表',
    permissions: [
      'report:view', 'report:export', 'report:sales', 'report:user',
      'product:view', 'order:view', 'user:view',
      'log:view'
    ],
    createTime: Date.now() - 30 * 24 * 60 * 60 * 1000
  }
];

// 管理员用户数据
export const mockAdminUsers = [
  {
    id: 1,
    username: 'superadmin',
    password: encryptPassword('admin'),
    nickname: '超级管理员',
    email: 'super@mall.com',
    phone: '13800000001',
    avatar: null,
    level: '铜牌会员',
    points: 520,
    status: 'active',
    roles: [mockRoles[0]],
    createTime: Date.now() - 365 * 24 * 60 * 60 * 1000,
    lastLoginTime: Date.now() - 2 * 60 * 60 * 1000,
    lastLoginIp: '192.168.1.100'
  },
  {
    id: 2,
    username: 'productadmin',
    password: encryptPassword('admin'),
    nickname: '商品管理员',
    email: 'product@mall.com',
    phone: '13800000002',
    avatar: null,
    status: 'active',
    roles: [mockRoles[1]],
    createTime: Date.now() - 180 * 24 * 60 * 60 * 1000,
    lastLoginTime: Date.now() - 5 * 60 * 60 * 1000,
    lastLoginIp: '192.168.1.101'
  },
  {
    id: 3,
    username: 'orderadmin',
    password: encryptPassword('admin'),
    nickname: '订单管理员',
    email: 'order@mall.com',
    phone: '13800000003',
    avatar: null,
    status: 'active',
    roles: [mockRoles[2]],
    createTime: Date.now() - 90 * 24 * 60 * 60 * 1000,
    lastLoginTime: Date.now() - 1 * 24 * 60 * 60 * 1000,
    lastLoginIp: '192.168.1.102'
  },
  {
    id: 4,
    username: 'service001',
    password: encryptPassword('admin'),
    nickname: '客服小张',
    email: 'service001@mall.com',
    phone: '13800000004',
    avatar: null,
    status: 'active',
    roles: [mockRoles[3]],
    createTime: Date.now() - 60 * 24 * 60 * 60 * 1000,
    lastLoginTime: Date.now() - 3 * 60 * 60 * 1000,
    lastLoginIp: '192.168.1.103'
  },
  {
    id: 5,
    username: 'analyst',
    password: encryptPassword('admin'),
    nickname: '数据分析师',
    email: 'analyst@mall.com',
    phone: '13800000005',
    avatar: null,
    status: 'active',
    roles: [mockRoles[4]],
    createTime: Date.now() - 30 * 24 * 60 * 60 * 1000,
    lastLoginTime: Date.now() - 6 * 60 * 60 * 1000,
    lastLoginIp: '192.168.1.104'
  }
];

// 商品分类数据（增强版）
export const mockCategories = [
  // 一级分类：电子数码
  {
    id: 1,
    name: '电子数码',
    code: 'electronics',
    parentId: null,
    icon: '💻',
    description: '电脑、手机、数码产品',
    sort: 1,
    status: 'active',
    createTime: Date.now() - 365 * 24 * 60 * 60 * 1000,
    productCount: 85
  },
  {
    id: 2,
    name: '手机通讯',
    code: 'mobile',
    parentId: 1,
    icon: '📱',
    description: '智能手机、功能机、配件',
    sort: 1,
    status: 'active',
    createTime: Date.now() - 300 * 24 * 60 * 60 * 1000,
    productCount: 45
  },
  {
    id: 3,
    name: '电脑办公',
    code: 'computer',
    parentId: 1,
    icon: '🖥️',
    description: '笔记本、台式机、办公设备',
    sort: 2,
    status: 'active',
    createTime: Date.now() - 300 * 24 * 60 * 60 * 1000,
    productCount: 25
  },
  {
    id: 4,
    name: '数码配件',
    code: 'accessories',
    parentId: 1,
    icon: '🎧',
    description: '耳机、音响、充电器等',
    sort: 3,
    status: 'active',
    createTime: Date.now() - 250 * 24 * 60 * 60 * 1000,
    productCount: 15
  },

  // 一级分类：家居生活
  {
    id: 5,
    name: '家居生活',
    code: 'home',
    parentId: null,
    icon: '🏠',
    description: '家具、家装、生活用品',
    sort: 2,
    status: 'active',
    createTime: Date.now() - 365 * 24 * 60 * 60 * 1000,
    productCount: 65
  },
  {
    id: 6,
    name: '家具',
    code: 'furniture',
    parentId: 5,
    icon: '🪑',
    description: '床、沙发、桌椅、柜子',
    sort: 1,
    status: 'active',
    createTime: Date.now() - 200 * 24 * 60 * 60 * 1000,
    productCount: 30
  },
  {
    id: 7,
    name: '生活日用',
    code: 'daily',
    parentId: 5,
    icon: '🧹',
    description: '清洁用品、收纳用品',
    sort: 2,
    status: 'active',
    createTime: Date.now() - 200 * 24 * 60 * 60 * 1000,
    productCount: 20
  },
  {
    id: 8,
    name: '家装建材',
    code: 'decoration',
    parentId: 5,
    icon: '🔨',
    description: '装修材料、工具',
    sort: 3,
    status: 'active',
    createTime: Date.now() - 180 * 24 * 60 * 60 * 1000,
    productCount: 15
  },

  // 一级分类：服装配饰
  {
    id: 9,
    name: '服装配饰',
    code: 'clothing',
    parentId: null,
    icon: '👔',
    description: '男装、女装、配饰',
    sort: 3,
    status: 'active',
    createTime: Date.now() - 365 * 24 * 60 * 60 * 1000,
    productCount: 120
  },
  {
    id: 10,
    name: '男装',
    code: 'mens',
    parentId: 9,
    icon: '👔',
    description: '男士服装',
    sort: 1,
    status: 'active',
    createTime: Date.now() - 150 * 24 * 60 * 60 * 1000,
    productCount: 50
  },
  {
    id: 11,
    name: '女装',
    code: 'womens',
    parentId: 9,
    icon: '👗',
    description: '女士服装',
    sort: 2,
    status: 'active',
    createTime: Date.now() - 150 * 24 * 60 * 60 * 1000,
    productCount: 55
  },
  {
    id: 12,
    name: '配饰',
    code: 'accessories_fashion',
    parentId: 9,
    icon: '👜',
    description: '包包、首饰、手表',
    sort: 3,
    status: 'active',
    createTime: Date.now() - 120 * 24 * 60 * 60 * 1000,
    productCount: 15
  },

  // 一级分类：食品饮料
  {
    id: 13,
    name: '食品饮料',
    code: 'food',
    parentId: null,
    icon: '🍔',
    description: '休闲食品、饮料酒水',
    sort: 4,
    status: 'active',
    createTime: Date.now() - 365 * 24 * 60 * 60 * 1000,
    productCount: 80
  },
  {
    id: 14,
    name: '休闲零食',
    code: 'snacks',
    parentId: 13,
    icon: '🍿',
    description: '坚果、薯片、糖果',
    sort: 1,
    status: 'active',
    createTime: Date.now() - 100 * 24 * 60 * 60 * 1000,
    productCount: 45
  },
  {
    id: 15,
    name: '饮料酒水',
    code: 'drinks',
    parentId: 13,
    icon: '🥤',
    description: '饮料、茶水、酒类',
    sort: 2,
    status: 'active',
    createTime: Date.now() - 100 * 24 * 60 * 60 * 1000,
    productCount: 35
  },

  // 一级分类：运动户外
  {
    id: 16,
    name: '运动户外',
    code: 'sports',
    parentId: null,
    icon: '⚽',
    description: '运动装备、户外用品',
    sort: 5,
    status: 'active',
    createTime: Date.now() - 200 * 24 * 60 * 60 * 1000,
    productCount: 40
  },
  {
    id: 17,
    name: '运动服装',
    code: 'sportswear',
    parentId: 16,
    icon: '👕',
    description: '运动服、运动鞋',
    sort: 1,
    status: 'active',
    createTime: Date.now() - 150 * 24 * 60 * 60 * 1000,
    productCount: 25
  },
  {
    id: 18,
    name: '户外装备',
    code: 'outdoor',
    parentId: 16,
    icon: '🎒',
    description: '登山包、帐篷、户外工具',
    sort: 2,
    status: 'active',
    createTime: Date.now() - 150 * 24 * 60 * 60 * 1000,
    productCount: 15
  }
];

// 商品数据（大幅增加数量和种类）
export const mockProducts = [
  // 手机通讯类（新增荣耀、一加机型）
  {
    id: 1,
    name: 'iPhone 15 Pro Max 256GB',
    categoryId: 2,
    price: 9999,
    originalPrice: 10999,
    subtitle: '手机热销榜第1名',
    description: '最新款苹果手机，A17 Pro芯片，钛金属设计，支持5G网络',
    images: [
      'https://g-search1.alicdn.com/img/bao/uploaded/i4/i4/3375251555/O1CN01f2c5Zy1NMEulrsZSv_!!3375251555.jpg_360x360q90.jpg_.webp',
      'https://img.alicdn.com/imgextra/i3/3375251555/O1CN01FRsg8l1NMElOtqW2r_!!3375251555.jpg_q50.jpg_.webp',
      'https://img.alicdn.com/imgextra/i2/3375251555/O1CN01MHq7i71NMElIR8rSy_!!3375251555.jpg_q50.jpg_.webp'
    ],
    stock: 50,
    sales: 128,
    views: 2580,
    status: 'active',
    createTime: Date.now() - 30 * 24 * 60 * 60 * 1000
  },
  {
    id: 2,
    name: 'Samsung Galaxy S24 Ultra',
    categoryId: 2,
    price: 8999,
    originalPrice: 9999,
    subtitle: '手机热销榜第2名',
    description: '三星旗舰手机，骁龙8 Gen 3处理器，200MP主摄',
    images: [
      'https://img.alicdn.com/imgextra/i1/2616970884/O1CN012Hl9pV1IOv2wMS9HI_!!2-item_pic.png_q50.jpg_.webp',
      'https://img.alicdn.com/imgextra/i1/2616970884/O1CN01d7wXyE1IOv2XzHOrV_!!2616970884.png_q50.jpg_.webp'
    ],
    stock: 35,
    sales: 89,
    views: 1850,
    status: 'active',
    createTime: Date.now() - 25 * 24 * 60 * 60 * 1000
  },
  {
    id: 3,
    name: '小米14 Pro 12GB+256GB',
    categoryId: 2,
    price: 4999,
    originalPrice: 5499,
    subtitle: '手机热销榜第3名',
    description: '徕卡光学镜头，第三代骁龙8处理器，120W快充',
    images: [
      'https://img.alicdn.com/imgextra/i3/909410026/O1CN014cs5I31C3xIaM5JOg_!!0-item_pic.jpg_q50.jpg_.webp',
      'https://img.alicdn.com/imgextra/i1/909410026/O1CN015QvpBp1C3xIVZl8SK_!!909410026.jpg_q50.jpg_.webp'  
    ],
    stock: 80,
    sales: 156,
    views: 3200,
    status: 'active',
    createTime: Date.now() - 20 * 24 * 60 * 60 * 1000
  },
  {
    id: 26, // 新增机型
    name: '荣耀Magic6 Pro',
    categoryId: 2,
    price: 5499,
    originalPrice: 5999,
    subtitle: '手机热销榜第4名',
    description: '骁龙8 Gen3，缪斯之眼3.0设计，2160Hz高频PWM调光',
    images: ['https://g-search1.alicdn.com/img/bao/uploaded/i4/i3/2162192073/O1CN010qjnwb1RBU2OSMDVL_!!2162192073.jpg_360x360q90.jpg_.webp'],
    stock: 60,
    sales: 98,
    views: 2200,
    status: 'active',
    createTime: Date.now() - 15 * 24 * 60 * 60 * 1000
  },

  // 电脑办公类（新增华为、华硕机型）
  {
    id: 5,
    name: 'MacBook Pro 16英寸 M3 Max',
    categoryId: 3,
    price: 29999,
    originalPrice: 32999,
    subtitle: '电脑热销榜第1名',
    description: '专业级笔记本电脑，M3 Max芯片，36GB内存，1TB存储',
    images: ['https://gw.alicdn.com/bao/uploaded/i2/835499526/O1CN01gXKHMd2KExsjN29wf_!!835499526.png_.webp',
      'https://img.alicdn.com/imgextra/i4/835499526/O1CN018jr0GA2KExogWBomG_!!835499526.jpg_q50.jpg_.webp'
    ],
    stock: 20,
    sales: 45,
    views: 1200,
    status: 'active',
    createTime: Date.now() - 45 * 24 * 60 * 60 * 1000
  },
  {
    id: 27, // 新增机型
    name: '华为MateBook X Pro 2024',
    categoryId: 3,
    price: 14999,
    originalPrice: 16999,
    subtitle: '电脑热销榜第2名',
    description: '3.2K触控屏，Intel i7-1360P，CNC一体化机身',
    images: ['https://gw.alicdn.com/bao/uploaded/i2/3584801780/O1CN0112JYNM1P1I3NCE12x_!!3584801780.jpg_.webp'],
    stock: 30,
    sales: 38,
    views: 1050,
    status: 'active',
    createTime: Date.now() - 30 * 24 * 60 * 60 * 1000
  },

  // 数码配件类（新增大疆、闪迪产品）
  {
    id: 8,
    name: '索尼 WH-1000XM5 头戴式降噪耳机',
    categoryId: 4,
    price: 2999,
    originalPrice: 3499,
    subtitle: '数码配件热销榜第1名',
    description: '旗舰级降噪耳机，30小时续航，支持LDAC高音质',
    images: ['https://g-search1.alicdn.com/img/bao/uploaded/i4/i2/2215645142919/O1CN01mxBXFw1XQwyM5FDuq_!!2215645142919.png_360x360q90.jpg_.webp'],
    stock: 100,
    sales: 189,
    views: 2850,
    status: 'active',
    createTime: Date.now() - 60 * 24 * 60 * 60 * 1000
  },
  {
    id: 28, // 新增产品
    name: '大疆 DJI OM 6 手机稳定器',
    categoryId: 4,
    price: 899,
    originalPrice: 999,
    subtitle: '数码配件热销榜第2名',
    description: '三轴防抖，智能跟随，支持横竖拍切换',
    images: ['https://g-search2.alicdn.com/img/bao/uploaded/i4/i3/2217644585407/O1CN011Gg1MN1poSSrLNAFf_!!2217644585407.jpg_360x360q90.jpg_.webp'],
    stock: 150,
    sales: 120,
    views: 1800,
    status: 'active',
    createTime: Date.now() - 20 * 24 * 60 * 60 * 1000
  },

  // 家具类（新增实木家具、智能家居）
  {
    id: 11,
    name: '宜家 MALM 马尔姆 双人床架',
    categoryId: 6,
    price: 1499,
    originalPrice: 1799,
    subtitle: '家具热销榜第1名',
    description: '简约北欧风格，白色橡木贴面，180x200cm',
    images: ['https://www.ikea.cn/cn/zh/images/products/malm-ma-er-mu-chuang-jia-gao-bai-se-xiang-mu-tie-mian__0638608_pe699032_s5.jpg',
      'https://g-search3.alicdn.com/img/bao/uploaded/i4/i2/34772218/O1CN01gkciEt1SFtRj3fk76_!!34772218.jpg_360x360q90.jpg_.webp'
    ],
    stock: 25,
    sales: 42,
    views: 760,
    status: 'active',
    createTime: Date.now() - 90 * 24 * 60 * 60 * 1000
  },
  {
    id: 29, // 新增产品
    name: '顾家家居 智能电动沙发',
    categoryId: 6,
    price: 12999,
    originalPrice: 15999,
    subtitle: '家具热销榜第2名',
    description: '真皮材质，多角度电动调节，USB充电接口',
    images: ['https://g-search2.alicdn.com/img/bao/uploaded/i4/i4/2219414738700/O1CN01VMj58U2E8eoX6sCRq_!!2219414738700.jpg_360x360q90.jpg_.webp'],
    stock: 10,
    sales: 8,
    views: 450,
    status: 'active',
    createTime: Date.now() - 60 * 24 * 60 * 60 * 1000
  },

  // 生活日用类（新增厨房电器、个护产品）
  {
    id: 13,
    name: '戴森 V15 Detect 无绳吸尘器',
    categoryId: 7,
    price: 4990,
    originalPrice: 5490,
    subtitle: '生活日用热销榜第1名',
    description: '激光探测微尘，智能吸力调节，60分钟续航',
    images: ['https://img.alicdn.com/img/i3/110091380/O1CN01Xs54r31M45c7Jgk29_!!4611686018427386996-0-saturn_solar.jpg_360x360q90.jpg_.webp'],
    stock: 35,
    sales: 67,
    views: 980,
    status: 'active',
    createTime: Date.now() - 40 * 24 * 60 * 60 * 1000
  },
  {
    id: 30, // 新增产品
    name: '九阳 破壁豆浆机',
    categoryId: 7,
    price: 599,
    originalPrice: 799,
    subtitle: '生活日用热销榜第2名',
    description: '10分钟快浆，静音降噪，冷热双杯',
    images: ['https://img.alicdn.com/img/i2/31698905/O1CN01e79tTA2FeY1mC9Udf_!!4611686018427383769-0-saturn_solar.jpg_360x360q90.jpg_.webp'],
    stock: 200,
    sales: 320,
    views: 4800,
    status: 'active',
    createTime: Date.now() - 10 * 24 * 60 * 60 * 1000
  },

  // 男装类（新增商务男装、运动品牌）
  {
    id: 15,
    name: '优衣库 男装 轻型羽绒服',
    categoryId: 10,
    price: 299,
    originalPrice: 399,
    subtitle: '男装热销榜第1名',
    description: '轻薄保暖，多色可选，90%白鸭绒填充',
    images: ['https://g-search2.alicdn.com/img/bao/uploaded/i4/i4/2208173019083/O1CN0117bfji2Gy4FOpivNP_!!2208173019083.jpg_360x360q90.jpg_.webp'],
    stock: 200,
    sales: 520,
    views: 6500,
    status: 'active',
    createTime: Date.now() - 15 * 24 * 60 * 60 * 1000
  },
  {
    id: 31, // 新增产品
    name: '七匹狼 男士商务西装套装',
    categoryId: 10,
    price: 1299,
    originalPrice: 1699,
    subtitle: '男装热销榜第2名',
    description: '羊毛混纺面料，修身剪裁，含西装+西裤+衬衫',
    images: ['https://img.alicdn.com/imgextra/i1/919786761/O1CN01yiXJ1I1zoaq6zIOA0_!!919786761-0-alimamacc.jpg_360x360q90.jpg_.webp'],
    stock: 80,
    sales: 58,
    views: 1200,
    status: 'active',
    createTime: Date.now() - 30 * 24 * 60 * 60 * 1000
  },

  // 休闲零食类（新增进口零食、健康食品）
  {
    id: 19,
    name: '三只松鼠 每日坚果大礼包',
    categoryId: 14,
    price: 89.9,
    originalPrice: 129.9,
    subtitle: '休闲零食热销榜第1名',
    description: '混合坚果，30包装，营养均衡',
    images: ['https://img.alicdn.com/img/i2/31536383/O1CN01elF9ph1x1T9N7pl0C_!!4611686018427385087-0-saturn_solar.jpg_360x360q90.jpg_.webp'],
    stock: 500,
    sales: 1580,
    views: 12000,
    status: 'active',
    createTime: Date.now() - 10 * 24 * 60 * 60 * 1000
  },
  {
    id: 32, // 新增产品
    name: '王饱饱 燕麦片 酸奶果粒味',
    categoryId: 14,
    price: 59.9,
    originalPrice: 79.9,
    subtitle: '休闲零食热销榜第2名',
    description: '烘焙非油炸，含冻干酸奶块，即食早餐',
    images: ['https://g-search1.alicdn.com/img/bao/uploaded/i4/i4/4070359042/O1CN01kFIYyx2GfIHI2aMxy_!!4611686018427379714-0-item_pic.jpg_360x360q90.jpg_.webp'],
    stock: 300,
    sales: 280,
    views: 3500,
    status: 'active',
    createTime: Date.now() - 5 * 24 * 60 * 60 * 1000
  },

  // 运动服装类（新增瑜伽服、户外品牌）
  {
    id: 23,
    name: 'Adidas 运动套装 男款',
    categoryId: 17,
    price: 599,
    originalPrice: 799,
    subtitle: '运动服装热销榜第1名',
    description: '透气面料，经典三条纹设计，适合运动休闲',
    images: ['https://img.alicdn.com/img/i4/127647693/O1CN013RBeEv26hRyzwGqzr_!!4611686018427387853-0-saturn_solar.jpg_360x360q90.jpg_.webp'],
    stock: 100,
    sales: 125,
    views: 2100,
    status: 'active',
    createTime: Date.now() - 35 * 24 * 60 * 60 * 1000
  },
  {
    id: 33, // 新增产品
    name: 'Lululemon 女士瑜伽裤',
    categoryId: 17,
    price: 850,
    originalPrice: 980,
    subtitle: '运动服装热销榜第2名',
    description: 'Nulu™面料，高腰设计，4-way stretch弹力',
    images: ['https://g-search1.alicdn.com/img/bao/uploaded/i4/i1/757495411/O1CN012FHEqR1pqI6Q19pnF_!!757495411.jpg_360x360q90.jpg_.webp'],
    stock: 60,
    sales: 45,
    views: 1500,
    status: 'active',
    createTime: Date.now() - 25 * 24 * 60 * 60 * 1000
  },

  // 新增品类：美妆护肤类
  {
    id: 34,
    name: '雅诗兰黛 小棕瓶精华 100ml',
    categoryId: 19,
    price: 899,
    originalPrice: 1199,
    subtitle: '美妆护肤热销榜第1名',
    description: '抗老修护，第七代小棕瓶，含 Chronolux™科技',
    images: ['https://img.alicdn.com/img/i3/172140044/O1CN01SubZ8C1CCCT7VzLen_!!4611686018427381260-0-saturn_solar.jpg_360x360q90.jpg_.webp'],
    stock: 50,
    sales: 32,
    views: 800,
    status: 'active',
    createTime: Date.now() - 40 * 24 * 60 * 60 * 1000
  },
  {
    id: 35,
    name: 'SK-II 神仙水 230ml',
    categoryId: 19,
    price: 1299,
    originalPrice: 1599,
    subtitle: '美妆护肤热销榜第2名',
    description: '含90%以上Pitera™，平衡水油，改善肤质',
    images: ['https://img.alicdn.com/img/i3/325160182/O1CN01PjzNRR1DDP8Q2Pnla_!!4611686018427383030-0-saturn_solar.jpg_360x360q90.jpg_.webp'],
    stock: 30,
    sales: 22,
    views: 650,
    status: 'active',
    createTime: Date.now() - 50 * 24 * 60 * 1000
  }
];

// 用户数据（增加数量和多样性）
export const mockUsers = [
  {
    id: 1,
    username: 'user001',
    password: '123456',
    nickname: '张三',
    phone: '13800138001',
    email: 'zhangsan@example.com',
    avatar: null,
    level: 'VIP',
    points: 2580,
    status: 'active',
    createTime: Date.now() - 365 * 24 * 60 * 60 * 1000,
    lastLoginTime: Date.now() - 2 * 60 * 60 * 1000
  },
  {
    id: 2,
    username: 'user002',
    password: '123456',
    nickname: '李四',
    phone: '13800138002',
    email: 'lisi@example.com',
    avatar: null,
    level: '金牌会员',
    points: 1860,
    status: 'active',
    createTime: Date.now() - 180 * 24 * 60 * 60 * 1000,
    lastLoginTime: Date.now() - 5 * 60 * 60 * 1000
  },
  {
    id: 3,
    username: 'user003',
    password: '123456',
    nickname: '王五',
    phone: '13800138003',
    email: 'wangwu@example.com',
    avatar: null,
    level: '银牌会员',
    points: 980,
    status: 'active',
    createTime: Date.now() - 90 * 24 * 60 * 60 * 1000,
    lastLoginTime: Date.now() - 1 * 24 * 60 * 60 * 1000
  },
  {
    id: 4,
    username: 'user004',
    password: '123456',
    nickname: '赵六',
    phone: '13800138004',
    email: 'zhaoliu@example.com',
    avatar: null,
    level: '铜牌会员',
    points: 520,
    status: 'active',
    createTime: Date.now() - 60 * 24 * 60 * 60 * 1000,
    lastLoginTime: Date.now() - 3 * 24 * 60 * 60 * 1000
  },
  {
    id: 5,
    username: 'user005',
    password: '123456',
    nickname: '钱七',
    phone: '13800138005',
    email: 'qianqi@example.com',
    avatar: null,
    level: '普通会员',
    points: 100,
    status: 'disabled',
    createTime: Date.now() - 30 * 24 * 60 * 60 * 1000,
    lastLoginTime: Date.now() - 7 * 24 * 60 * 60 * 1000
  },
  {
    id: 6,
    username: 'user006',
    password: '123456',
    nickname: '孙八',
    phone: '13800138006',
    email: 'sunba@example.com',
    avatar: null,
    level: 'VIP',
    points: 3200,
    status: 'active',
    createTime: Date.now() - 200 * 24 * 60 * 60 * 1000,
    lastLoginTime: Date.now() - 1 * 60 * 60 * 1000
  },
  {
    id: 7,
    username: 'user007',
    password: '123456',
    nickname: '周九',
    phone: '13800138007',
    email: 'zhoujiu@example.com',
    avatar: null,
    level: '金牌会员',
    points: 1650,
    status: 'active',
    createTime: Date.now() - 120 * 24 * 60 * 60 * 1000,
    lastLoginTime: Date.now() - 4 * 60 * 60 * 1000
  },
  {
    id: 8,
    username: 'user008',
    password: '123456',
    nickname: '吴十',
    phone: '13800138008',
    email: 'wushi@example.com',
    avatar: null,
    level: '银牌会员',
    points: 890,
    status: 'active',
    createTime: Date.now() - 45 * 24 * 60 * 60 * 1000,
    lastLoginTime: Date.now() - 6 * 60 * 60 * 1000
  }
];

// 售后数据（增加更多案例）
export const mockRefunds = [
  {
    id: 1,
    refundNo: 'REF202401150001',
    orderNo: 'ORD202401140001',
    userId: 1,
    userName: '张三',
    userPhone: '13800138001',
    type: 'refund_only',
    status: 'pending',
    reason: '商品质量问题',
    description: '收到的手机屏幕有划痕，要求退款',
    productId: 1,
    productName: 'iPhone 15 Pro Max 256GB',
    productImage: 'https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/iphone-15-pro-max-blue-titanium-select?wid=470&hei=556&fmt=png-alpha&.v=1693009278906',
    productPrice: 9999,
    productSpec: '蓝色钛金属',
    quantity: 1,
    refundAmount: 9999,
    images: [],
    createTime: Date.now() - 2 * 24 * 60 * 60 * 1000
  },
  {
    id: 2,
    refundNo: 'REF202401150002',
    orderNo: 'ORD202401130002',
    userId: 2,
    userName: '李四',
    userPhone: '13800138002',
    type: 'refund_return',
    status: 'approved',
    reason: '商品与描述不符',
    description: '实际收到的颜色与图片不一致',
    productId: 15,
    productName: '优衣库 男装 轻型羽绒服',
    productImage: 'https://image.uniqlo.com/UQ/ST3/AsianCommon/imagesgoods/449830/item/goods_56_449830.jpg',
    productPrice: 299,
    productSpec: '黑色 L',
    quantity: 2,
    refundAmount: 598,
    images: [],
    createTime: Date.now() - 3 * 24 * 60 * 60 * 1000,
    reviewTime: Date.now() - 2 * 24 * 60 * 60 * 1000,
    reviewResult: 'approved',
    returnAddress: '北京市朝阳区xxx路xxx号 收件人：售后部 电话：010-12345678'
  },
  {
    id: 3,
    refundNo: 'REF202401140003',
    orderNo: 'ORD202401120003',
    userId: 3,
    userName: '王五',
    userPhone: '13800138003',
    type: 'exchange',
    status: 'completed',
    reason: '尺码不合适',
    description: '衣服偏小，需要换大一码',
    productId: 17,
    productName: 'ZARA 女士连衣裙',
    productImage: 'https://static.zara.net/photos///2024/V/0/1/p/2298/044/800/2/w/1126/2298044800_1_1_1.jpg',
    productPrice: 399,
    productSpec: '黑色 M',
    quantity: 1,
    refundAmount: 0,
    images: [],
    createTime: Date.now() - 5 * 24 * 60 * 60 * 1000,
    reviewTime: Date.now() - 4 * 24 * 60 * 60 * 1000,
    completeTime: Date.now() - 1 * 24 * 60 * 60 * 1000,
    reviewResult: 'approved'
  },
  {
    id: 4,
    refundNo: 'REF202401130004',
    orderNo: 'ORD202401110004',
    userId: 4,
    userName: '赵六',
    userPhone: '13800138004',
    type: 'refund_only',
    status: 'rejected',
    reason: '不喜欢',
    description: '买了不喜欢，想要退款',
    productId: 8,
    productName: '索尼 WH-1000XM5 头戴式降噪耳机',
    productImage: 'https://www.sony.com.cn/content/dam/sonyportal/products/headphones/wh-1000xm5/images/Black/wh-1000xm5_black_01.jpg',
    productPrice: 2999,
    productSpec: '黑色',
    quantity: 1,
    refundAmount: 2999,
    images: [],
    createTime: Date.now() - 6 * 24 * 60 * 60 * 1000,
    reviewTime: Date.now() - 5 * 24 * 60 * 60 * 1000,
    reviewResult: 'rejected',
    reviewRemark: '商品无质量问题，不支持个人喜好原因退款'
  },
  {
    id: 5,
    refundNo: 'REF202401120005',
    orderNo: 'ORD202401100005',
    userId: 6,
    userName: '孙八',
    userPhone: '13800138006',
    type: 'refund_return',
    status: 'processing',
    reason: '商品损坏',
    description: '快递运输过程中包装破损，商品受损',
    productId: 5,
    productName: 'MacBook Pro 16英寸 M3 Max',
    productImage: 'https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/mbp16-spaceblack-select-202310?wid=904&hei=840&fmt=jpeg&qlt=90&.v=1697311054290',
    productPrice: 29999,
    productSpec: '深空灰',
    quantity: 1,
    refundAmount: 29999,
    images: [],
    createTime: Date.now() - 8 * 24 * 60 * 60 * 1000,
    reviewTime: Date.now() - 7 * 24 * 60 * 60 * 1000,
    reviewResult: 'approved',
    returnAddress: '北京市朝阳区xxx路xxx号 收件人：售后部 电话：010-12345678'
  }
];

// 生成更多示例订单数据
const generateSampleOrders = () => {
  const orders = [];
  const statuses = ['pending', 'paid', 'shipped', 'delivered', 'cancelled'];
  const paymentMethods = ['alipay', 'wechat', 'bankcard'];
  
  for (let i = 1; i <= 1; i++) {
    const userId = Math.floor(Math.random() * 8) + 1;
    const user = mockUsers.find(u => u.id === userId);
    const status = statuses[Math.floor(Math.random() * statuses.length)];
    const createTime = Date.now() - Math.floor(Math.random() * 30) * 24 * 60 * 60 * 1000;
    
    // 随机选择1-3个商品
    const itemCount = Math.floor(Math.random() * 3) + 1;
    const items = [];
    let totalAmount = 0;
    
    for (let j = 0; j < itemCount; j++) {
      const product = mockProducts[Math.floor(Math.random() * mockProducts.length)];
      const quantity = Math.floor(Math.random() * 3) + 1;
      const price = product.price;
      
      items.push({
        id: product.id,
        name: product.name,
        spec: '默认规格',
        price: price,
        quantity: quantity
      });
      
      totalAmount += price * quantity;
    }
    
    const order = {
      id: i,
      orderNo: `ORD${Date.now().toString().slice(-10)}${i.toString().padStart(3, '0')}`,
      userId: userId,
      userName: user?.nickname || `用户${userId}`,
      userPhone: user?.phone || `1380013800${userId}`,
      address: [
        '北京市朝阳区建国路88号SOHO现代城',
        '上海市浦东新区陆家嘴金融中心',
        '广州市天河区珠江新城',
        '深圳市南山区科技园',
        '杭州市西湖区文三路'
      ][Math.floor(Math.random() * 5)],
      items: items,
      totalAmount: totalAmount,
      paymentMethod: paymentMethods[Math.floor(Math.random() * paymentMethods.length)],
      status: status,
      createTime: createTime
    };
    
    // 根据状态设置相应的时间戳
    if (status !== 'pending') {
      order.payTime = createTime + Math.floor(Math.random() * 60) * 60 * 1000;
    }
    if (status === 'shipped' || status === 'delivered') {
      order.shipTime = order.payTime + Math.floor(Math.random() * 24) * 60 * 60 * 1000;
      order.logistics = ['顺丰速运', '中通快递', '圆通速递', '申通快递'][Math.floor(Math.random() * 4)];
      order.trackingNumber = `SF${Date.now().toString().slice(-10)}`;
    }
    if (status === 'delivered') {
      order.deliverTime = order.shipTime + Math.floor(Math.random() * 72) * 60 * 60 * 1000;
    }
    
    orders.push(order);
  }
  
  return orders;
};

// 生成更多示例日志数据
const generateSampleLogs = () => {
  const logs = [];
  const modules = ['system', 'product', 'order', 'user', 'category', 'refund', 'role'];
  const actions = ['login', 'logout', 'create', 'update', 'delete', 'view'];
  const operators = ['超级管理员', '商品管理员', '订单管理员', '客服小张', '数据分析师'];
  const ips = ['192.168.1.100', '192.168.1.101', '192.168.1.102', '192.168.1.103', '192.168.1.104'];
  const locations = ['北京', '上海', '广州', '深圳', '杭州'];
  
  for (let i = 1; i <= 1; i++) {
    const module = modules[Math.floor(Math.random() * modules.length)];
    const action = actions[Math.floor(Math.random() * actions.length)];
    const operator = operators[Math.floor(Math.random() * operators.length)];
    
    const log = {
      id: i,
      module: module,
      action: action,
      content: `${action === 'login' ? '登录系统' : `${action} ${module}`}`,
      operator: operator,
      operatorId: Math.floor(Math.random() * 5) + 1,
      createTime: Date.now() - Math.floor(Math.random() * 7 * 24) * 60 * 60 * 1000,
      ipAddress: ips[Math.floor(Math.random() * ips.length)],
      device: ['Windows PC', 'Mac', 'Mobile Device'][Math.floor(Math.random() * 3)],
      browser: ['Chrome', 'Safari', 'Firefox', 'Edge'][Math.floor(Math.random() * 4)],
      location: locations[Math.floor(Math.random() * locations.length)],
      duration: Math.floor(Math.random() * 200) + 50,
      result: Math.random() > 0.1 ? 'success' : 'fail'
    };
    
    logs.push(log);
  }
  
  return logs.sort((a, b) => b.createTime - a.createTime);
};

// 初始化数据函数
export const initializeMockData = () => {
  console.log('🚀 开始初始化商城数据...');

  // 初始化商品数据
  const existingProducts = localStorage.getItem('mall_products');
  if (!existingProducts) {
    localStorage.setItem('mall_products', JSON.stringify(mockProducts));
    console.log(`✅ 初始化商品数据: ${mockProducts.length} 件商品`);
  }
  
  // 初始化分类数据
  const existingCategories = localStorage.getItem('mall_categories');
  if (!existingCategories) {
    localStorage.setItem('mall_categories', JSON.stringify(mockCategories));
    console.log(`✅ 初始化分类数据: ${mockCategories.length} 个分类`);
  }
  
  // 强制更新管理员用户数据
  localStorage.setItem('mall_admin_users', JSON.stringify(mockAdminUsers));
  console.log(`✅ 初始化管理员数据: ${mockAdminUsers.length} 个管理员`);
  
  // 初始化用户数据
  const existingUsers = localStorage.getItem('mall_users');
  if (!existingUsers) {
    localStorage.setItem('mall_users', JSON.stringify(mockUsers));
    console.log(`✅ 初始化用户数据: ${mockUsers.length} 个用户`);
  } else {
    // 确保初始化的示例用户数据存在
    const users = JSON.parse(existingUsers);
    let updated = false;
    
    // 检查是否需要添加示例用户
    for (const mockUser of mockUsers) {
      const userExists = users.some(u => u.username === mockUser.username);
      if (!userExists) {
        users.push(mockUser);
        updated = true;
      }
    }
    
    if (updated) {
      localStorage.setItem('mall_users', JSON.stringify(users));
      console.log(`✅ 更新用户数据: ${users.length} 个用户`);
    }
  }
  
  // 初始化售后数据
  const existingRefunds = localStorage.getItem('mall_refunds');
  if (!existingRefunds) {
    localStorage.setItem('mall_refunds', JSON.stringify(mockRefunds));
    console.log(`✅ 初始化售后数据: ${mockRefunds.length} 个售后单`);
  }
  
  // 初始化订单数据
  const existingOrders = localStorage.getItem('mall_admin_orders');
  if (!existingOrders) {
    const sampleOrders = generateSampleOrders();
    localStorage.setItem('mall_admin_orders', JSON.stringify(sampleOrders));
    console.log(`✅ 初始化订单数据: ${sampleOrders.length} 个订单`);
  }
  
  // 初始化日志数据
  const existingLogs = localStorage.getItem('mall_logs');
  if (!existingLogs) {
    const sampleLogs = generateSampleLogs();
    localStorage.setItem('mall_logs', JSON.stringify(sampleLogs));
    console.log(`✅ 初始化日志数据: ${sampleLogs.length} 条日志`);
  }

  console.log('🎉 商城数据初始化完成！');
  console.log('📊 数据统计:');
  console.log(`   - 商品: ${mockProducts.length} 件`);
  console.log(`   - 分类: ${mockCategories.length} 个`);
  console.log(`   - 管理员: ${mockAdminUsers.length} 个`);
  
  const currentUsers = JSON.parse(localStorage.getItem('mall_users') || '[]');
  console.log(`   - 用户: ${currentUsers.length} 个`);
  
  console.log(`   - 售后: ${mockRefunds.length} 个`);
  console.log(`   - 订单: 50 个`);
  console.log(`   - 日志: 100 条`);
};